#!/bin/bash
clear

RED="\033[1;31m"
GREEN="\033[1;32m"
YELLOW="\033[1;33m"
BLUE="\033[1;34m"
PLAIN="\033[0m"

if [ "${EUID}" -ne 0 ]; then
    echo -e "${RED}You need to run this script as root!${PLAIN}" && exit 1
fi

echo "====================== [ SSHD: CLIENT LOGIN ]"
echo "PID | Username | Ip address"
echo "---------------------------------------------"
cat "/var/log/auth.log" | grep -i dropbear | grep -i "Password auth succeeded" > /tmp/dropbear_login.txt;
getServiceID=($( ps aux | grep -i dropbear | awk '{print $2}' ))
for dpi in "${getServiceID[@]}"
do
	cat /tmp/dropbear_login.txt | grep "dropbear\[$dpi\]" > /tmp/dropbear_login_pid.txt;
	getUserName=$(cat /tmp/dropbear_login_pid.txt | awk '{print $10}')
	getUserAddr=$(cat /tmp/dropbear_login_pid.txt | awk '{print $12}')
	totalClient=$(cat /tmp/dropbear_login_pid.txt | wc -l)
	[[ $totalClient -eq 1 ]] && echo "$dpi - $getUserName - $getUserAddr"
done
echo "---------------------------------------------"
echo "Copyright 2021 Cybertize, Allright Reserved."
echo "============================================="
echo "";
echo "";
echo "=================== [ OPENVPN: CLIENT LOGIN ]"
echo "Username | Ip address | Login"
echo "---------------------------------------------"
if [ -f "/var/log/openvpn/openvpn-auth.log" ]
then
	line=`cat /var/log/openvpn/openvpn-auth.log | wc -l`
	a=$(( 3 + ((line - 8) / 2) )) && b=$(( (line - 8) / 2 ))
	cat /var/log/openvpn/ovpn-auth.log | head -n $a | tail -n $b | cut -d "," -f 1,2,5 | sed -e 's/,/   /g' > /tmp/vpn-login-db.txt
	cat /tmp/vpn-login-db.txt
fi
echo "---------------------------------------------"
echo "Copyright 2021 Cybertize, Allright Reserved."
echo "============================================="
echo "";
